public class Main {
    public static void main(String[] args) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("1234");
        System.out.println(stringBuffer);
        StringBuilder stringBuilder = new StringBuilder("hello");
        stringBuilder.append("world");
        stringBuilder.append("123").append("abc");
        System.out.println(stringBuilder);
        String str = stringBuilder.toString();
        System.out.println(str);
        String str2 = "1234";
        StringBuilder stringBuilder22 = new StringBuilder(str2);
        System.out.println(stringBuilder22);
        StringBuilder stringBuilder222 = new StringBuilder();
        stringBuilder222.append(str2);
        System.out.println(stringBuilder222);
    }

    public static void main13(String[] args) {
        /*String s = "hello";
        s += " world";//s指向了 新的对象  s = s + " world";
        System.out.println(s);//helloworld
        */
        String s = "hello";
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(s);
        stringBuilder.append(" world");
        s = stringBuilder.toString();
        System.out.println(s);
    }



    public static void main12(String[] args) {
        final char[] value = {'a','b','c','d'};
        value[0] = 'g';//修改对象 0 下标内容
        //value = new char[10];//指向新的对象



    }
    public static void main11(String[] args) {
        long start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 100000; ++i){
            sbf.append(i);
        }

        long end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 100000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();//获取当前系统的时间戳
        String s = "";
        for(int i = 0; i < 100000; ++i){
            //以后不能在循环当中 这样去拼接字符串
            s += i;
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }
    public static void main10(String[] args) {
        String s = "abafgh";
        String ret = s.substring(1,3);
        System.out.println(ret);
        System.out.println("========");
        String s1 = "    agg  dg  gga gg    ";
        String ret2 = s1.trim();
        System.out.println(ret2);
    }
    public static void main9(String[] args) {
        String str = "name=zhangsan&age=18" ;
        String[] s = str.split("&");
        for (String x:s) {
           // System.out.println(x);
            String[] ss =x.split("=");
            for (String st:ss ) {
                System.out.println(st);
            }
        }

    }
    public static void main8(String[] args) {
        String s ="hello world hello xx";
        String[] ret = s.split(" ",2);
        for (int i = 0;i < ret.length;i++)
        System.out.println(ret[i]);

        String s1 = "190.153.2.2";
        String[] ret1 = s1.split("\\.");
        for (int i = 0;i < ret1.length;i++)

        System.out.println(ret1);
    }
    public static void main7(String[] args) {
         String s = "ababdhvhab";
       String ret = s.replace('a','g');
        System.out.println(ret);

        String ret1 = s.replace("ab","gggg");
        System.out.println(ret1);
        String ret2 = s.replaceFirst("ab","gggg");
        System.out.println(ret2);
    }
    public static void main6(String[] args) {
      String s = String.valueOf(123);
        System.out.println(s);

        int a = Integer.parseInt("123");
        System.out.println(a);


        String s1 = "hello";
        String ret = s1.toUpperCase();
        System.out.println(ret);
        String s2 = "HELLO";
        String ret1 = s2.toLowerCase();
        System.out.println(ret1);


        String s3 = "hello";
        char[] ch = s3.toCharArray();
        for (char c:ch) {
            System.out.println(c);
        }
        String s4 = String.format("%d-%d-%d",2011,6,9);
        System.out.println(s4);
    }
    public static void main5(String[] args) {
        String s = new String("hello");
        char ch = s.charAt(0);//注意不能越界
        System.out.println(ch);

        int index =s.indexOf("l",3);
        System.out.println(index);

        int index1 =s.indexOf("ll",2);
        System.out.println(index1);
        System.out.println("==========");
        String s1 = new String("hello");
        int index2 = s1.lastIndexOf("l");
        System.out.println(index2);
    }
    public static void main4(String[] args) {
        String s = new String("hello");
        String s1 = new String("Hello");
        System.out.println(s.compareToIgnoreCase(s1));


    }
    public static void main3(String[] args) {
        String s = new String("hello");
        String s1 = new String("bello");
        System.out.println(s.compareTo(s1));
    }
    public static void main2(String[] args) {
        String str = new String("hello");
        String str1 = new String("hello");
        System.out.println(str.equals(str1));

        String s = "hello";
        String s1 = "hello";
        System.out.println(s==s1);//hello被放入了常量池
        System.out.println(s.equals(s1));


    }
    public static void main1(String[] args){
     String str = "fighing";
     String str1 = new String("fighing");
        System.out.println(str);
        System.out.println(str1);

        char[] array = {'a','b','c'};
        String str2 = new String(array);
        System.out.println(str2);

        String str3 = "";
        System.out.println(str3);
        System.out.println(str3.length());
        System.out.println(str3.isEmpty());

        String str4 = null;
        System.out.println(str4);
        System.out.println(str4.isEmpty());
        System.out.println(str4.length());





    }

}